<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聘书模版工具</title>
    <link rel="stylesheet" href="../css/all.min.css">
    <style>
        :root {
            --primary-color: #1a56a5;
            --secondary-color: #e8f0fe;
            --accent-color: #d4a017;
            --text-color: #333333;
            --light-text: #666666;
            --border-color: #e0e0e0;
            --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f8f9fa;
            color: var(--text-color);
            line-height: 1.6;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            gap: 2rem;
            width: 100%;
        }
        
        @media (min-width: 992px) {
            .container {
                flex-direction: row;
            }
        }
        
        .left-section, .right-section {
            background-color: #ffffff;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 1rem 2rem 0 2rem;
            position: relative;
        }
        
        @media (min-width: 992px) {
            .left-section {
                width: 40%;
            }
            .right-section {
                width: 60%;
            }
        }
        
        h1 {
            font-size: 1.25rem;
            font-weight: 700;
            text-align: center;
            color: var(--primary-color);
            margin-bottom: 0.5rem;
            position: relative;
        }
        
        h1::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 3px;
            background-color: var(--accent-color);
            border-radius: 3px;
        }
        
        .error-message {
            color: #d32f2f;
            font-size: 0.875rem;
            margin-bottom: 1rem;
            display: none;
            background-color: #fce4ec;
            padding: 10px;
            border-radius: 6px;
            text-align: center;
        }
        
        .form-group {
            margin-bottom: 1rem; 
        }
        
        label {
            display: block;
            font-size: 0.875rem;
            font-weight: 500;
            color: var(--text-color);
            margin-bottom: 0.25rem; 
        }
        
        label.required::after {
            content: '*';
            color: #d32f2f;
            margin-left: 4px;
        }
        
        input, select, textarea {
            width: 100%;
            padding: 0.5rem; 
            border: 1px solid var(--border-color);
            border-radius: 8px;
            font-size: 0.875rem;
            font-family: inherit;
            transition: all 0.3s ease;
        }
        
        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(26, 86, 165, 0.2);
        }
        
        #certificate {
            background-color: #fff;
            border: 1px solid #e0e0e0;
            border-radius: 0;
            padding: 3rem;
            position: relative;
            min-height: 500px;
        }
        
        #certificate::before {
            content: '';
            position: absolute;
            top: 20px;
            left: 20px;
            right: 20px;
            bottom: 20px;
            border: 2px solid var(--primary-color);
            pointer-events: none;
            z-index: 0;
        }
        
        #certificate h2 {
            font-size: 2.5rem;
            font-weight: 700;
            color: var(--primary-color);
            text-align: center;
            margin: 2rem 0;
            position: relative;
        }
        
        #certificate h2::after {
            content: '';
            position: absolute;
            bottom: -15px;
            left: 50%;
            transform: translateX(-50%);
            width: 100px;
            height: 2px;
            background-color: var(--accent-color);
        }
        
        #certificate p {
            font-size: 1.125rem;
            color: var(--text-color);
            margin-bottom: 1.5rem;
            line-height: 1.8;
            position: relative;
            z-index: 1;
            text-indent: 2rem;
        }
        
        .text-center {
            text-align: center;
        }
        
        .text-left {
            text-align: left;
        }
        
        .text-right {
            text-align: right;
        }
        
        .signature-area {
            margin-top: 3rem;
            display: flex;
            justify-content: space-between;
        }
        
        .company-seal {
            width: 120px;
            height: 120px;
            border: 2px dashed var(--accent-color);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--accent-color);
            font-size: 0.875rem;
            margin-left: auto;
        }
        
        .fixed-buttons {
            position: fixed;
            right: 2rem;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 1rem;
            z-index: 100;
        }
        
        button {
            padding: 0.75rem 1.5rem;
            border: none;
            border-radius: 8px;
            font-size: 0.875rem;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 8px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        
        button.generate {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #ffffff;
        }
        
        button.generate:hover {
            background: linear-gradient(135deg, #556bc9 0%, #6a3d91 100%);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }
        
        button.reset {
            background-color: #9e9e9e;
            color: #ffffff;
        }
        
        button.reset:hover {
            background-color: #808080;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }
        
        button.download {
            background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
            color: #ffffff;
        }
        
        button.download:hover {
            background: linear-gradient(135deg, #6a3d91 0%, #556bc9 100%);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }
        
        .form-actions {
            display: flex;
            gap: 1rem;
            margin-top: 1.5rem;
        }
        
        .form-actions button {
            flex: 1;
        }
        
        @media print {
            body * {
                visibility: hidden;
            }
            #certificate, #certificate * {
                visibility: visible;
            }
            #certificate {
                position: absolute;
                left: 0;
                top: 0;
                width: 210mm; 
                height: 297mm;
                border: none;
                background-image: none;
                padding: 20mm;
                margin: 0;
                box-sizing: border-box;
                transform: scale(1);
                transform-origin: top left;
                font-size: 14px;
            }
            #certificate h2 {
                font-size: 28px;
            }
            #certificate p {
                font-size: 14px;
            }
            .fixed-buttons {
                display: none;
            }
            .no-print {
                display: none;
            }
        }
        
        .certificate-content {
            position: relative;
            z-index: 1;
        }
        
        .form-header {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .form-header i {
            color: var(--primary-color);
            font-size: 1.5rem;
        }
        
        .preview-header {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .preview-header i {
            color: var(--primary-color);
            font-size: 1.5rem;
        }
        
        .form-section {
            border-bottom: 1px solid #f0f0f0;
        }
        
        .form-section-title {
            font-size: 1rem;
            font-weight: 600;
            color: var(--primary-color);
            margin-bottom: 1rem;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .form-section-title i {
            font-size: 1rem;
        }
        
        .radio-group {
            display: flex;
            gap: 1rem;
            margin-bottom: 1rem;
        }
        
        .radio-option {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .radio-option input {
            width: auto;
        }
        
        .radio-option label {
            margin-bottom: 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="left-section">
            <div class="form-header">
                <i class="fas fa-cog"></i>
                <h1>聘书设置</h1>
            </div>
            <p class="error-message" id="errorMessage"><i class="fas fa-exclamation-circle"></i> 请填写所有必填信息！</p>
            <form id="certificateForm">
                <div class="form-section">
                    <div class="form-section-title">
                        <i class="fas fa-user"></i>
                        <span>基本信息</span>
                    </div>
                    <div class="form-group">
                        <label for="employeeName" class="required">受聘人姓名</label>
                        <input type="text" id="employeeName" placeholder="请输入受聘人姓名">
                    </div>
                    <div class="form-group">
                        <label for="gender">性别</label>
                        <div class="radio-group">
                            <div class="radio-option">
                                <input type="radio" id="genderMale" name="gender" value="先生" checked>
                                <label for="genderMale">先生</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="genderFemale" name="gender" value="女士">
                                <label for="genderFemale">女士</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="position" class="required">受聘职位</label>
                        <input type="text" id="position" placeholder="请输入受聘职位">
                    </div>
                </div>
                
                <div class="form-section">
                    <div class="form-section-title">
                        <i class="fas fa-building"></i>
                        <span>公司信息</span>
                    </div>
                    <div class="form-group">
                        <label for="companyName" class="required">公司名称</label>
                        <input type="text" id="companyName" placeholder="请输入公司名称">
                    </div>
                    <div class="form-group">
                        <label for="department">所属部门</label>
                        <input type="text" id="department" placeholder="请输入所属部门(可选)">
                    </div>
                </div>
                
                <div class="form-section">
                    <div class="form-section-title">
                        <i class="fas fa-calendar-alt"></i>
                        <span>聘用期限</span>
                    </div>
                    <div class="form-group">
                        <label for="startDate" class="required">起始日期</label>
                        <input type="text" id="startDate" placeholder="请输入起始日期（格式：XXXX年XX月XX日）">
                    </div>
                    <div class="form-group">
                        <label for="endDate" class="required">结束日期</label>
                        <input type="text" id="endDate" placeholder="请输入结束日期（格式：XXXX年XX月XX日）">
                    </div>
                </div>
                
            </form>
        </div>
        
        <div class="right-section">
            <div class="preview-header">
                <i class="fas fa-eye"></i>
                <h1>聘书预览</h1>
            </div>
            <div id="certificate">
                <div class="certificate-content">
                    <h2>聘 书</h2>
                    <p>致：<span id="certEmployeeName">________</span></p>
                    <p>经研究决定，特聘请 <span id="certEmployeeName2">________</span> 担任 <span id="certCompanyName">________</span> 的 <span id="certPosition">________</span>，聘期自 <span id="certStartDate">________</span> 至 <span id="certEndDate">________</span>。</p>
                    <p>此聘。</p>
                    <p class="text-right">聘任方（盖章）：<span id="certCompanyName2">__________________</span></p>
                    <p class="text-right">法定代表人（签字）：____________________</p>
                    <p class="text-right">日期：________年____月____日</p>
                    <p class="text-right">受聘人（签字）：____________________</p>
                    <p class="text-right">日期：________年____月____日</p>
                </div>
            </div>
        </div>
    </div>
    
    <div class="fixed-buttons no-print">
        <button type="button" onclick="generateCertificate()" class="generate">
            <i class="fas fa-magic"></i> 生成
        </button>
        <button type="button" onclick="resetForm()" class="reset">
            <i class="fas fa-redo"></i> 重置
        </button>
        <button type="button" onclick="downloadCertificate()" class="download">
            <i class="fas fa-download"></i> 下载
        </button>
    </div>
    
    <script src="../js/html2canvas.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const today = new Date();
            const formattedToday = `${today.getFullYear()}年${String(today.getMonth() + 1).padStart(2, '0')}月${String(today.getDate()).padStart(2, '0')}日`;
            const nextYear = new Date();
            nextYear.setFullYear(today.getFullYear() + 1);
            const formattedNextYear = `${nextYear.getFullYear()}年${String(nextYear.getMonth() + 1).padStart(2, '0')}月${String(nextYear.getDate()).padStart(2, '0')}日`;

            document.getElementById('startDate').value = formattedToday;
            document.getElementById('endDate').value = formattedNextYear;
        });

        function generateCertificate() {
            const employeeName = document.getElementById('employeeName').value;
            const position = document.getElementById('position').value;
            const companyName = document.getElementById('companyName').value;
            const startDate = document.getElementById('startDate').value;
            const endDate = document.getElementById('endDate').value;
            const gender = document.querySelector('input[name="gender"]:checked').value;
            const department = document.getElementById('department').value;

            const errorMessage = document.getElementById('errorMessage');

            if (!employeeName || !position || !companyName || !startDate || !endDate) {
                errorMessage.style.display = 'block';
                return;
            }

            errorMessage.style.display = 'none';
            
            // 更新聘书内容
            document.getElementById('certEmployeeName').textContent = employeeName;
            document.getElementById('certEmployeeName2').textContent = employeeName;
            document.getElementById('certPosition').textContent = position;
            document.getElementById('certCompanyName').textContent = companyName;
            document.getElementById('certCompanyName2').textContent = companyName;
            document.getElementById('certStartDate').textContent = startDate;
            document.getElementById('certEndDate').textContent = endDate;

            const today = new Date();
            const currentYear = today.getFullYear();
            const currentMonth = String(today.getMonth() + 1).padStart(2, '0');
            const currentDay = String(today.getDate()).padStart(2, '0');
        }

        function downloadCertificate() {
            generateCertificate();
            const employeeName = document.getElementById('employeeName').value;
            const certificate = document.getElementById('certificate');
            html2canvas(certificate).then(canvas => {
                const link = document.createElement('a');
                link.download = `${employeeName}聘书.png`;
                link.href = canvas.toDataURL('image/png');
                link.click();
            });
        }

        function resetForm() {
            const form = document.getElementById('certificateForm');
            form.reset();

            const today = new Date();
            const formattedToday = `${today.getFullYear()}年${String(today.getMonth() + 1).padStart(2, '0')}月${String(today.getDate()).padStart(2, '0')}日`;
            const nextYear = new Date();
            nextYear.setFullYear(today.getFullYear() + 1);
            const formattedNextYear = `${nextYear.getFullYear()}年${String(nextYear.getMonth() + 1).padStart(2, '0')}月${String(nextYear.getDate()).padStart(2, '0')}日`;

            document.getElementById('startDate').value = formattedToday;
            document.getElementById('endDate').value = formattedNextYear;

            document.getElementById('certEmployeeName').textContent = '________';
            document.getElementById('certEmployeeName2').textContent = '________';
            document.getElementById('certPosition').textContent = '________';
            document.getElementById('certCompanyName').textContent = '________';
            document.getElementById('certCompanyName2').textContent = '________';
            document.getElementById('certStartDate').textContent = '________';
            document.getElementById('certEndDate').textContent = '________';
            document.getElementById('certDate').textContent = '________';
            document.getElementById('certDateEmployee').textContent = '________';

            const errorMessage = document.getElementById('errorMessage');
            errorMessage.style.display = 'none';
        }
    </script>
</body>
</html>